﻿package mortal.game.view.mining.render
{
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.core.frame.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.systemSetting.*;

    public class MiningRefleshStarRender extends NoSkinCellRenderer
    {
        private var _bg:ScaleBitmap;
        private var _txtName:GTextFiled;
        private var _txtType:GTextFiled;
        private var _stars:MiningStar;
        private var _txtHelpTimes:GTextFiled;
        private var _btnAskHelp:GLoadingButton;
        private var _timer:Timer;
        private var _myData:STaskRoutineTaskOtherPlayersInfo;
        public static var lastClickTime:int = 0;

        public function MiningRefleshStarRender()
        {
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._myData = (param1 as MiningRefreshStartData).info;
            if (this._bg != null)
            {
                this._bg.dispose();
            }
            if ((param1 as MiningRefreshStartData).isBlack)
            {
                this._bg = UIFactory.bg(0, 0, 274, 54, this, ImagesConst.GuildTaskRenderBg0);
            }
            else
            {
                this._bg = UIFactory.bg(0, 0, 274, 54, this, ImagesConst.GuildTaskRenderBg1);
            }
            this.addChildAt(this._bg, 0);
            var _loc_2:* = this._myData.player;
            this._txtName.text = _loc_2.name;
            this._txtType.text = GameDefConfig.instance.getItem("EGuildPostion", this._myData.position).text;
            this._stars.updateStars((this._myData.color - 1), this._myData.star);
            this._txtHelpTimes.text = this._myData.help.toString() + "/" + GameConst.TRoutineTaskRefreshCount;
            this.updateHelpAndAskHelpStatus();
            return;
        }// end function

        private function updateHelpAndAskHelpStatus() : void
        {
            var _loc_1:Boolean = false;
            if (this._myData.help >= GameConst.TRoutineTaskRefreshCount || Cache.instance.mining.isMaxColor || Cache.instance.mining.getMiningTask() == null || !Cache.instance.mining.getMiningTask().isDoing())
            {
                this._btnAskHelp.mouseEnabled = false;
                this._btnAskHelp.filters = [FilterConst.colorFilter];
                EffectManager.glowFilterUnReg(this._btnAskHelp);
            }
            else
            {
                this._btnAskHelp.mouseEnabled = true;
                this._btnAskHelp.filters = [];
                _loc_1 = ClientSetting.local.getIsDone(IsDoneType.hasGuideMining);
                if (!_loc_1 && this._myData != null && !Cache.instance.mining.hasAskForHel(this._myData.player.entityId.id))
                {
                    EffectManager.glowFilterReg(this._btnAskHelp);
                    setTimeout(this.nextFrameToSave, 300);
                }
            }
            return;
        }// end function

        private function nextFrameToSave() : void
        {
            ClientSetting.local.setIsDone(true, IsDoneType.hasGuideMining);
            ClientSetting.save(true);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._txtName = UIFactory.gTextField("", 5, 6, 100, 20, this);
            this._txtName.textColor = 65280;
            this._txtType = UIFactory.gTextField("[]", 5, this._txtName.y + 21, 100, 20, this);
            this._stars = UICompomentPool.getUICompoment(MiningStar) as MiningStar;
            this._stars.x = 103;
            this._stars.y = 17;
            this._stars.isCenter = false;
            this.addChild(this._stars);
            this._txtHelpTimes = UIFactory.gTextField("", 173, 14, 100, 20, this);
            this._txtHelpTimes.textColor = 16777215;
            this._btnAskHelp = UIFactory.gLoadingButton(ImagesConst.MiningAskForHelpBtn_upSkin, 204, 15, 67, 23, this);
            this._btnAskHelp.configEventListener(MouseEvent.CLICK, this.askHelpHandler);
            return;
        }// end function

        private function askHelpHandler(event:MouseEvent) : void
        {
            var _loc_2:* = FrameManager.flashFrame.getTime();
            if (_loc_2 - lastClickTime < 300)
            {
                MsgManager.showRollTipsMsg(Language.getString(21037));
                return;
            }
            lastClickTime = _loc_2;
            GameProxy.task.miningAskForHelp(this._myData.player.entityId.id);
            this.enableAll(false);
            this.addTimer();
            MsgManager.showRollTipsMsg(Language.getString(21038));
            EffectManager.glowFilterUnReg(this._btnAskHelp);
            Cache.instance.mining.setAskedForHel(this._myData.player.entityId.id);
            return;
        }// end function

        private function enableAll(param1:Boolean) : void
        {
            if (param1)
            {
                this._btnAskHelp.mouseEnabled = true;
                this._btnAskHelp.filters = [];
            }
            else
            {
                this._btnAskHelp.mouseEnabled = false;
                this._btnAskHelp.filters = [FilterConst.colorFilter];
            }
            return;
        }// end function

        private function timerHandler(event:TimerEvent) : void
        {
            if (isDisposed)
            {
                return;
            }
            this.updateHelpAndAskHelpStatus();
            return;
        }// end function

        private function addTimer() : void
        {
            if (this._timer == null)
            {
                this._timer = new Timer(500, 1);
                this._timer.addEventListener(TimerEvent.TIMER_COMPLETE, this.timerHandler);
            }
            this._timer.start();
            return;
        }// end function

        private function removeTimer() : void
        {
            if (this._timer != null)
            {
                this._timer.removeEventListener(TimerEvent.TIMER_COMPLETE, this.timerHandler);
                this._timer.stop();
                this._timer = null;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            EffectManager.glowFilterUnReg(this._btnAskHelp);
            this.removeTimer();
            this._txtName.dispose(param1);
            this._txtName = null;
            this._txtType.dispose(param1);
            this._txtType = null;
            this._stars.dispose(param1);
            this._stars = null;
            this._txtHelpTimes.dispose(param1);
            this._txtHelpTimes = null;
            this._btnAskHelp.dispose(param1);
            this._btnAskHelp = null;
            if (this._bg != null)
            {
                this._bg.dispose();
                this._bg = null;
            }
            return;
        }// end function

    }
}
